#include "systemc.h"

#define PACMAX 128

SC_MODULE(output){
public:
	sc_in_clk clock;
	sc_out<bool> req;
	sc_in<bool> ack;
	sc_out< sc_lv<8> > data;

	
	sc_lv<1> sendFlag;
	sc_lv<4> interHorizontal;
	sc_lv<4> interVertical;
	sc_lv<8> interNumber;
	sc_lv<8> interData;

	sc_lv<8> direction;
	int stan;

	void doit(){
		while(1){
			if(sendFlag == "1" ){
				
				if( ack.read() == 0){
					cout << "@"<< sc_time_stamp() << " INPUT: "<<endl;
					cout << "Stan : " << stan << endl;
					req.write("1");
					if(stan == 0){
						direction.range(7,4) = interHorizontal;
						direction.range(3,0) = interVertical;	
						data.write(direction);
						stan++;

					}else if(stan == 1){
						data.write(interNumber);
						stan++;
					}else if(stan >=2){
						// stan-2  aktualny pakiet
						data.write(interData);

						stan++;
						if(stan-2 >=interNumber.to_int() ) stan = 0;
					}
					wait();
					req.write("0");
				}else {
					wait();
				}
			}
		}
	}


	SC_CTOR(output){
		stan = 0;
		SC_CTHREAD(doit, clock.pos() );
	}
};